var setVal = -80;

document.onkeydown = function () {
	var tag = window.event.target || window.event.srcElement;
	if (tag.tagName.toLowerCase() == "textarea") {
		/*if(window.event.keyCode!=13){
            return;
        }else{
            window.event = $(this).val()+'\r\n';
            $(this).val(window.event).focus();
        }*/
		return;
    } else {
    	if (window.event && window.event.keyCode == 13) {
            window.event.returnValue = false;
        }
    }
    
}

function startInit(iframeId) {
	window.setInterval("reinitIframe('" + iframeId + "')", 100);
} 

function reinitIframe(iframeId){
	var iframe = document.getElementById(iframeId);
	try{
		iframe.height = iframe.contentWindow.document.documentElement.scrollHeight
	}catch (ex){
		
	}
}

function reinitParentIframe(iframeId){
	var iframe = parent.window.document.getElementById(iframeId);
	iframe.height = 0;
	try{
		iframe.height = iframe.contentWindow.document.documentElement.scrollHeight*1.05;
	}catch (ex){
		
	}
}

var pageobj = null;
var visiblePages = 10;
var totalpage = 0;
var pages = ",";
var pageStr = "";
var methodStr = "";

function getShowPages() {
	if(pageobj != null){
		pages = ",";
		var currentPage = pageobj.pageIndex;
	    var startPage;
	    var section = parseInt(currentPage / visiblePages, 10);
	    if (currentPage % visiblePages === 0) {
	        startPage = (section - 1) * visiblePages + 1;
	    } else {
	        startPage = section * visiblePages + 1;
	    }
	
	    var endPage = Math.min(pageobj.totalPages, (startPage + visiblePages) - 1);
	    for (var i = startPage; i <= endPage; i++) {
	        pages += i + ",";
	    }
	    
	    totalpage = pageobj.totalPages;
	}
         
}

function createPages(pagediv,pages,index,suffixName){
	if("" == methodStr){
		methodStr = "to_submit";
	}
	if(pageobj != null){
		pageStr = "";
		var currentPage = pageobj.pageIndex;
		
		var firstclickStr = ""
		var lastclickStr = "";
		if(pageobj.firstPage){
			firstclickStr = "";
		}
		else{
			if(index == 0){
				firstclickStr = methodStr + "(" + (currentPage - 1) + ")";
			}
			else{
				firstclickStr = methodStr + "(" + (currentPage - 1) + "," + index + ")";
			}
		}
		
		if(pageobj.lastPage){
			lastclickStr = "";
		}
		else{
			if(index == 0){
				lastclickStr = methodStr + "(" + (currentPage + 1) + ")";
			}	
			else{
				lastclickStr = methodStr + "(" + (currentPage + 1) + "," + index + ")";
			}
		}
		
		var firstclass = (currentPage == 1)?"disabled" : "";
		pageStr += "<li class=\"" + firstclass + "\">"
	   		+ "<a href=\"javascript:void(0)\" onclick=\"" + firstclickStr + "\">上一页</a></li>";
	       
	    var nowtypeclass = "";
	    var nowclickStr = "";
	    for(var i=1;i<=pageobj.totalPages;i++){
	    	var tmpnum = "," + i + ",";
	    	if(i == currentPage){       		
	    		nowtypeclass = "show_div active";
	    		nowclickStr = "";
	    	}
	    	else{
	    		var tmpindex = pages.indexOf(tmpnum);
	    		if(tmpindex > -1){
	    			nowtypeclass = "show_div";
	    		}
	    		else{
	    			nowtypeclass = "hidden_div"
	    		}
	    		
	    		if(index == 0){
	    			nowclickStr = methodStr + "(" + i + ")"; 
	    		}
	    		else{
	    			nowclickStr = methodStr + "(" + i + "," + index + ")";
	    		}
	    	}
	    	
	    	pageStr += "<li class=\"" + nowtypeclass + "\">"
	    			+ "<a href=\"javascript:void(0);\" onclick=\"" + nowclickStr + "\"><span>" + i + "</span></a></li>";
	    	
	    }
	    
	    pageStr += "<li class=\"totalPage\">"
			+ "<a href=\"javascript:void(0)\" style=\"color:#777;\">共" + totalpage + "页"
			+ "</a></li>" ;
	    
	    var lastclass = (currentPage >= pageobj.totalPages)?"disabled" : "";
	   	pageStr += "<li class=\"" + lastclass + "\">"
	   			+ "<a href=\"javascript:void(0)\" onclick=\"" + lastclickStr + "\">下一页</a></li>";	
	   
	    
	   	var targerStr = "";
	   	if(null == suffixName){
	   		targerStr = "targerPage";
	   	}
	   	else{
	   		targerStr = "targerPage_" + suffixName;
	   	}
	    pageStr += "<li class=\"totalPage\"><a>到&nbsp;"
			+ "<input id=\"" + targerStr + "\" name=\"" + targerStr + "\" type=\"text\" style=\"width:30px;height:30px;margin-top:-8px;border: 1px solid #ddd;\"/>"
			+ "&nbsp;页</a><a href=\"javascript:void(0)\" class=\"btn\" style=\"background-color:#337ab7;border-color:#337ab7;color:white;\" onclick=\"if(checkNum('" + targerStr + "'," + totalpage + ")){" + methodStr + "($('#" + targerStr + "').val());}\">确定</a>"
			+ "</li>";
	    
	   
		$("#" + pagediv).html(pageStr); 
	}
}

function isPositiveInteger(s){//是否为正整数
    var re = /^[0-9]+$/ ;
    return re.test(s)
}  

function checkNum(tmpid,tmptotal){
	var tmppage = $("#" + tmpid).val();
	if("" != tmppage){
		if(!isPositiveInteger(tmppage)){
			$("#" + tmpid).val("");
			alert("请输入正确的页数!");	
			return false;
		}　　
		else{
			if(tmppage > tmptotal){
				$("#" + tmpid).val("");
				alert("超过最大页数!");
				return false;
			}
			else{
				return true;
			}
		}
	}
	else{
		return false;
	}
}

function initPages(pagediv,index){
	getShowPages();
	createPages(pagediv,pages,index);  	
}

function initPagesAndMethod(pagediv,index,methodName){
	methodStr = methodName;
	getShowPages();
	createPages(pagediv,pages,index,null);  
}

function initPagesAndMethod1(pagediv,index,methodName,suffixName){
	methodStr = methodName;
	getShowPages();
	createPages(pagediv,pages,index,suffixName);  
}

var pageobjarr = new Array();
var pagesarr = new Array();
var totalpagearr = new Array();
function getMutilShowPages() {
	if(pageobjarr.length != 0){
		pagesarr = new Array();
		totalpagearr = new Array();
		for(var i=0;i<pageobjarr.length;i++){
			var tmpobj = pageobjarr[i];
			pages = ",";
			var currentPage = tmpobj.pageIndex;
		    var startPage;
		    var section = parseInt(currentPage / visiblePages, 10);
		    if (currentPage % visiblePages === 0) {
		        startPage = (section - 1) * visiblePages + 1;
		    } else {
		        startPage = section * visiblePages + 1;
		    }
		
		    var endPage = Math.min(tmpobj.totalPages, (startPage + visiblePages) - 1);
		    for (var j = startPage; j <= endPage; j++) {
		    	pages += j + ",";
		    }
		    pagesarr[i] = pages;
		    totalpagearr[i] = tmpobj.totalPages;
		}
		
	}        
}
function createMutilPages(pagediv,pages,index){
	if(pageobjarr.length != 0){
		var tmpdiv = "";
		for(var i=0;i<pageobjarr.length;i++){
			if(i==0){
				tmpdiv = pagediv;
			}
			else{
				tmpdiv = pagediv + i;
			}
			
			var tmpobj = pageobjarr[i];
			pageStr = "";
			var currentPage = tmpobj.pageIndex;
			
			var firstclickStr = ""
			var lastclickStr = "";
			if(tmpobj.firstPage){
				firstclickStr = "";
			}
			else{
				if(index == 0){
					firstclickStr = "to_submit(" + (currentPage - 1) + ")";
				}
				else{
					firstclickStr = "to_submit(" + (currentPage - 1) + "," + index + ")";
				}
			}
			
			if(tmpobj.lastPage){
				lastclickStr = "";
			}
			else{
				if(index == 0){
					lastclickStr = "to_submit(" + (currentPage + 1) + ")";
				}	
				else{
					lastclickStr = "to_submit(" + (currentPage + 1) + "," + index + ")";
				}
			}
			
			var firstclass = (currentPage == 1)?"disabled" : "";
			pageStr += "<li class=\"" + firstclass + "\">"
		   		+ "<a href=\"javascript:void(0)\" onclick=\"" + firstclickStr + "\">上一页</a></li>";
		       
		    var nowtypeclass = "";
		    var nowclickStr = "";
		    pages = pagesarr[i];
		    for(var j=1;j<=tmpobj.totalPages;j++){
		    	var tmpnum = "," + j + ",";
		    	if(j == currentPage){       		
		    		nowtypeclass = "show_div active";
		    		nowclickStr = "";
		    	}
		    	else{
		    		var tmpindex = pages.indexOf(tmpnum);
		    		if(tmpindex > -1){
		    			nowtypeclass = "show_div";
		    		}
		    		else{
		    			nowtypeclass = "hidden_div"
		    		}
		    		
		    		if(index == 0){
		    			nowclickStr = "to_submit(" + j + ")"; 
		    		}
		    		else{
		    			nowclickStr = "to_submit(" + j + "," + index + ")";
		    		}
		    	}
		    	
		    	pageStr += "<li class=\"" + nowtypeclass + "\">"
		    			+ "<a href=\"javascript:void(0);\" onclick=\"" + nowclickStr + "\"><span>" + j + "</span></a></li>";
		    	
		    }
		    
		    
		    pageStr += "<li class=\"totalPage\">"
				+ "<a href=\"javascript:void(0)\" style=\"color:#777;\">共" + totalpagearr[i] + "页"
				+ "</a></li>" ;
		    
		    var lastclass = (currentPage >= tmpobj.totalPages)?"disabled" : "";
		   	pageStr += "<li class=\"" + lastclass + "\">"
		   			+ "<a href=\"javascript:void(0)\" onclick=\"" + lastclickStr + "\">下一页</a></li>";
		   
		    
		    pageStr += "<li class=\"totalPage\"><a>到&nbsp;"
				+ "<input id=\"targerPage_" + i +"\" name=\"targerPage_" + i + "\" type=\"text\" style=\"width:30px;height:30px;margin-top:-8px;border: 1px solid #ddd;\"/>"
				+ "&nbsp;页</a><button class=\"btn\" style=\"background-color:#337ab7;border-color:#337ab7;\" onclick=\"if(checkNum('targerPage_" + i + "'," + totalpagearr[i] + ")){to_submit($('#targerPage_" + i + "').val());}\">确定</button>"
				+ "</li>";
		    
		  /*  pageStr += "<li class=\"totalPage\">"
				+ "<a href=\"javascript:void(0)\">共" + totalpagearr[i] + "页"
				+ "</a>&nbsp;<a>到&nbsp;"
				+ "<input id=\"targerPage\" name=\"targerPage\" type=\"text\" style=\"width:20px;height:25px;margin-top:-8px;border: 1px solid #ddd;\" onblur=\"if(checkNum(this.value," + totalpagearr[i] + ")){to_submit(this.value);}\"/>"
				+ "&nbsp;页</a>"
				+ "</li>";*/
		   
		  
				
			$("#" + tmpdiv).html(pageStr); 
		}
	}
}
function initMutilPages(pagediv,index){
	getMutilShowPages();
	createMutilPages(pagediv,pages,index);  	
}

var ids = ",";//所有选中状态
function check_all(obj,cname){ 	
	$("input[name='" + cname + "']").each(function(){ 
		if(!this.disabled){
			if(obj.checked){//选中
				var tmpval = "," + $(this).val() + ",";
				var tmpindex = ids.indexOf(tmpval);
				if(tmpindex < 0){
					ids += $(this).val() + ",";
				}			
			}
			this.checked=obj.checked;
		}		
	}); 
	
	if(!obj.checked){
		ids = ",";
	}
}

function changeChecked(obj,cname,num){
	var tmpid = "";
	if(cname != null){
		tmpid = "#" + cname;
	}
	var tmpval = "," + $(obj).val() + ",";
	var tmpindex = ids.indexOf(tmpval);
	
	if(obj.checked){//选中
		if(tmpindex < 0){
			ids += $(obj).val() + ","
		}
		else{
			
		}
		
		if(cname != null){
			var idarr = ids.substring(1,ids.length-1).split(",");

			if(idarr.length == num){
				$(tmpid).prop("checked", true);
			}
		}
	}
	else{//未选中
		if(tmpindex < 0){
			
		}
		else{
			ids = ids.substring(0,tmpindex) + ids.substring(tmpindex + tmpval.length -1);
		}
		
		if(cname != null){
			$(tmpid).prop("checked", false);
		}
	}
}
function to_search(optflag){
	var tmpval = "";
	var tmpurl = "";
	if(optflag <= 2){
		tmpval = $("#goodsSearch").val();
		tmpurl= "/goods/searchGift";
	}else if(optflag == 3){
		tmpval = $("#goodsSearch1").val();
		tmpurl = "/marketing/searchHotBook";
	}else if(optflag == 4){
		tmpval = $("#goodsSearch2").val();
		tmpurl = "/marketing/searchHotCourse";
	}else if(optflag == 5){	
		tmpval = $("#goodsSearch3").val();
		tmpurl = "/marketing/searchHotMedia";
	}
	if("" != tmpval){
		$.ajax({ 
			url: tmpurl, 
			type: "post",
			data: {goodsSearch:tmpval,opt:optflag},  
			dataType: "json",
			success: function(datas){
				var objs = "";
				if(optflag <= 2){
					objs = datas.giftList;
				}else if(optflag == 3){
					objs = datas.hotBook;
				}else if(optflag == 4){
					objs = datas.hotCourse;
				}else if(optflag == 5){	
					objs = datas.hotMedia;
				}
				toFillDatas(objs,optflag);
	     	},
			error: function (jqXHR, textStatus, errorThrown) {
				alert(errorThrown);
			}
		});
	}  
	else{
		if(optflag <= 2){
			alert("请输入商品名称或编号！");
		}else if(optflag == 3){
			alert("输入书名、作者名或ISBN！");
		}else if(optflag == 4){
			alert("请输入课程商品名称或商品ID！");
		}else if(optflag == 5){		
			alert("请输入有声书商品名称或商品ID！");
		}
	}
}
function toFillDatas(objs,optflag){
	var datas = objs;
	var tmplen = datas.length; 
	var num = 0;
	var tmpul = "";
	if(optflag <= 2){
		tmpul = "#goods_list";
	}
	else{
		num = parseInt(optflag) - 2;

		tmpul = "#goods_list" + num;
	}
	
	$(tmpul).find("li").remove();
	
	for(i=0; i<tmplen ; i++){
		addLi(datas[i],optflag);
	}
}
function addLi(obj,optflag){
	var num = 0;
	var tmpul = "";
	if(optflag <= 2){
		tmpul = "#goods_list";
	}
	else{
		num = parseInt(optflag) - 2;
		tmpul = "#goods_list" + num; 
	}  
    
    var tmpstr = "";  
    
    if(optflag<=2){
       tmpstr = "<li><a href=\"#\" onclick=\"to_select(" + obj.id + ",'" + obj.goodsNum + "','" + EscapeChar(obj.goodsName) + "'," + obj.goodsCategory + "," + obj.goodsPrice + ")\">" + obj.goodsNum + " " + obj.goodsName + "</a></li>";
    }else if(optflag == 3){
       tmpstr = "<li><a href=\"#\" onclick=\"to_select1(" + obj.id + ",'" + obj.isbnnum + "','" + EscapeChar(obj.bookName) + "')\">" + obj.isbnnum + " " + obj.bookName + "</a></li>";	
    }else if(optflag == 4){
       tmpstr = "<li><a href=\"#\" onclick=\"to_select2(" + obj.id + ",'" + EscapeChar(obj.goodsName) + "')\">" + obj.id + " " + obj.goodsName + "</a></li>";	
    }else if(optflag == 5){
       tmpstr = "<li><a href=\"#\" onclick=\"to_select3(" + obj.id + ",'" + EscapeChar(obj.goodsName) + "')\">" + obj.id + " " + obj.goodsName + "</a></li>";
    }

    $(tmpul).append(tmpstr);
}

var obj = null;
function to_select(id,num,gname,gtype,price){
	obj = new Object(); 
	obj.id = id; 
	obj.num = num; 
	obj.gname = gname;
	obj.gtype = gtype;
	obj.price = price;

	$("#goods_show").html(num + " " + gname);
	
	$("#search_goods").removeClass("show_div");
	$("#search_goods").addClass("hidden_div");
	
	$("#select_show").removeClass("hidden_div");
	$("#select_show").addClass("show_div");
}
function to_select1(id,num,bName){
	obj = new Object(); 
	obj.id = id; 
	obj.num = num; 
	obj.bName = bName;
	
	$("#goods_show1").html(num + " " + bName);
	
	$("#search_goods1").removeClass("show_div");
	$("#search_goods1").addClass("hidden_div");
	
	$("#select_show1").removeClass("hidden_div");
	$("#select_show1").addClass("show_div");
}
function to_select2(id,gname){
	obj = new Object(); 
	obj.id = id; 
	obj.gname = gname;
	
	$("#goods_show2").html(id + " " + gname);
	
	$("#search_goods2").removeClass("show_div");
	$("#search_goods2").addClass("hidden_div");
	
	$("#select_show2").removeClass("hidden_div");
	$("#select_show2").addClass("show_div");
}
function to_select3(id,gname){
	obj = new Object(); 
	obj.id = id; 
	obj.gname = gname;
	
	$("#goods_show3").html(id + " " + gname);
	
	$("#search_goods3").removeClass("show_div");
	$("#search_goods3").addClass("hidden_div");
	
	$("#select_show3").removeClass("hidden_div");
	$("#select_show3").addClass("show_div");
}
function cancel_goods(){
	obj = null;	
	nextSearch(0);
}

function cancel_hot_goods(num){
	obj = null;	
	nextSearch(num);
}

function nextSearch(num){
	if(num == 0){
		$("#search_goods").removeClass("hidden_div");
		$("#search_goods").addClass("show_div");
	
		$("#select_show").removeClass("show_div");
		$("#select_show").addClass("hidden_div");
	}
	else{
		$("#search_goods" + num).removeClass("hidden_div");
		$("#search_goods" + num).addClass("show_div");
	
		$("#select_show" + num).removeClass("show_div");
		$("#select_show" + num).addClass("hidden_div");
	}
	
}

function to_cancel(){
	$(".editobj").each(function(){
		$(this).val("");
	});
	
	$(".editobj_box").each(function(){
		$(this).attr("checked",false);	
	});
	
	to_cacelError();
}

function to_cacelError(){
	$(".error").each(function(){
		var tmpclass = $(this).attr("class");
		if("error" == tmpclass){
			$(this).remove();
		}	
	});
}


function to_enableForm(formid){
	$("#" + formid + " .error").each(function(){
		var tmpclass = $(this).attr("class");
		if("error" == tmpclass){
			$(this).remove();
		}	
	});
}

function setAudioUrl(obj){
	var objUrl = getObjectURL(obj.files[0]);
    $("#audio").attr("src", objUrl);
    $("#audio").show();
    getTime();
}
function getObjectURL(file) {
    var url = null;
    if (window.createObjectURL != undefined) { // basic
        url = window.createObjectURL(file);
    } else if (window.URL != undefined) { // mozilla(firefox)
        url = window.URL.createObjectURL(file);
    } else if (window.webkitURL != undefined) { // webkit or chrome
        url = window.webkitURL.createObjectURL(file);
    }
    return url;
}
function getTime() {
    setTimeout(function () {
        var duration = $("#audio")[0].duration;
        if(isNaN(duration)){
            getTime();
        }
        else{
        	time = $("#audio")[0].duration;
        }
    }, 10);
}

function initLeftMenu(funcList){  
	var tmphtml = "";
	var pid = 0;
	var pcode = "";
	for(var i=0;i<funcList.length;i++){
		var sysFunc = funcList[i];
	
		if(sysFunc.permissionLevel == 2){
			if(null == sysFunc.permissionLink ||  "" == sysFunc.permissionLink){
				tmphtml = '<li id="' + sysFunc.permissionCode + '_' +  sysFunc.permissionLevel+ '" class="pmenu"  onclick="changeStatus(\'' + sysFunc.permissionCode + '\',' + sysFunc.permissionLevel + ',true);">'
				 + '<a id="' + sysFunc.id + '"><img src="' + sysFunc.permissionIcon + '" width="26px" height="26px"/>'
				 + '<span class="first_lev_title">' + sysFunc.permissionName + '</span>'
				 //+ '<span class="fa fa-chevron-down"></span>'
				 + '</a><li>';
			}
			else{
				tmphtml = '<li id="' + sysFunc.permissionCode + '_' +  sysFunc.permissionLevel+ '" class="mars_menu pmenu" onclick="changeStatus(\'' + sysFunc.permissionCode + '\',' + sysFunc.permissionLevel + ',true);changeMarsMenu(this,null,true);">'
				 + '<a id="' + sysFunc.id + '" href="' + sysFunc.permissionLink +'" target="ifm1"><img src="' + sysFunc.permissionIcon + '" width="26px" height="26px"/>'
				 + '<span class="first_lev_title">' + sysFunc.permissionName + '</span>'
				 + '</a><li>';
			}
			$("#allmenus").append(tmphtml);
		    
		}
		
		if(sysFunc.permissionLevel == 3){
			if(sysFunc.pid != pid){
				pid = sysFunc.pid;
				
				var code = $("#" + sysFunc.pid).parent().attr("id");
				pcode = code.replace("_" + (sysFunc.permissionLevel-1),"");
							
				tmpHtml = '<ul id="' + pcode + '_' + sysFunc.permissionLevel + '" class="nav child_menu hiddenMenu">'
						+ '<li id="' + pcode + '_' + sysFunc.id + '" class="mars_menu" onclick="changeMarsMenu(this,null,true);">';
				
				if(null == sysFunc.permissionLink ||  "" == sysFunc.permissionLink){
					tmpHtml += '<a id="' + sysFunc.id + '">' + sysFunc.permissionName + '</a>';
				}
				else{
					tmpHtml += '<a id="' + sysFunc.id + '" href="' + sysFunc.permissionLink + '" target="ifm1">' + sysFunc.permissionName + '</a>';
				}
				
				
				
				tmpHtml += '</li></ul>';
				$("#" + sysFunc.pid).parent().append(tmpHtml);
				$("#" + sysFunc.pid).append('<span class="fa fa-chevron-down"></span>');
			}
			else{
				tmpHtml = '<li id="' + pcode + '_' + sysFunc.id + '" class="mars_menu" onclick="changeMarsMenu(this,null,true);">';
				
				if(null == sysFunc.permissionLink ||  "" == sysFunc.permissionLink){
					tmpHtml += '<a id="' + sysFunc.id + '">' + sysFunc.permissionName + '</a>';
				}
				else{
					tmpHtml += '<a id="' + sysFunc.id + '" href="' + sysFunc.permissionLink + '" target="ifm1">' + sysFunc.permissionName + '</a>';
				}
				
				tmpHtml += "</li>";
				
				$("#" + pcode + "_" + sysFunc.permissionLevel).append(tmpHtml);
			}
		}
		
		if(sysFunc.permissionLevel >= 4){
			if(sysFunc.pid != pid){
				pid = sysFunc.pid;
				
				
				var code = $("#" + sysFunc.pid).parent().attr("id");
				pcode = code;
				
				var lastlevel = sysFunc.permissionLevel -1;
				
				$("#" + sysFunc.pid).append('<span class="fa fa-chevron-down"></span>');
				$("#" + sysFunc.pid).parent().addClass("pmenu");
				$("#" + sysFunc.pid).parent().attr("id",code + "_" + lastlevel);
				$("#" + sysFunc.pid).parent().attr("onclick","changeMarsMenu(this," + lastlevel + ",false);");
				

				tmpHtml = '<ul id="' + pcode + '_' + sysFunc.permissionLevel + '" class="nav child_menu child_menu_' + sysFunc.permissionLevel + ' hiddenMenu">'
						+ '<li id="' + pcode + '_' + sysFunc.id + '" class="mars_menu" onclick="changeMarsMenu(this,null,false);">';
				if(null == sysFunc.permissionLink ||  "" == sysFunc.permissionLink){
					tmpHtml += '<a id="' + sysFunc.id + '">' + sysFunc.permissionName + '</a>';
				}
				else{
					tmpHtml += '<a id="' + sysFunc.id + '" href="' + sysFunc.permissionLink + '" target="ifm1">' + sysFunc.permissionName + '</a>';
				}
				tmpHtml += '</li></ul>';
				$("#" + sysFunc.pid).parent().append(tmpHtml);
			}
			else{
				tmpHtml = '<li id="' + pcode + '_' + sysFunc.id + '" class="mars_menu" onclick="changeMarsMenu(this,null,false);">';
				
				if(null == sysFunc.permissionLink ||  "" == sysFunc.permissionLink){
					tmpHtml += '<a id="' + sysFunc.id + '">' + sysFunc.permissionName + '</a>';
				}
				else{
					tmpHtml += '<a id="' + sysFunc.id + '" href="' + sysFunc.permissionLink + '" target="ifm1">' + sysFunc.permissionName + '</a>';
					
				}
				
				tmpHtml += "</li>";
				
				$("#" + pcode + "_" + sysFunc.permissionLevel).append(tmpHtml);
			}
		}
		
	}
}

function colorRGBtoHex(color) {
    var rgb = color.split(',');
    var r = parseInt(rgb[0].split('(')[1]);
    var g = parseInt(rgb[1]);
    var b = parseInt(rgb[2].split(')')[0]);
    var hex = ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
    return hex;
 }

